//1.引入vue
import Vue from 'vue'
//2.引入 vue-router
import VueRouter from 'vue-router'
//3.在vue中使用vuerouter
Vue.use(VueRouter)


//通过路由懒加载引入路由组件
const Home = () => import('@/pages/Home')
const Register = () => import('@/pages/Register')
const Login = () => import('@/pages/Login')
const Search = () => import('@/pages/Search')
const Detail = () => import('@/pages/Detail')
const AddCartSuccess = () => import('@/pages/AddCartSuccess')
const ShopCart = () => import('@/pages/ShopCart')

//重写push 多次点击search时,已经在search界面了,但是再点就会弹出promise的报错,是因为没有处理promise异常

const lastPush = VueRouter.prototype.push
VueRouter.prototype.push = function myPush(location, onComplete = () => { }, onAbort = () => { }) {
  return lastPush.call(this, location, onComplete, onAbort)
}


//配置路由


export default new VueRouter({
  mode: 'history',
  routes: [
    { path: '/home', component: Home, name: 'home' },
    {
      path: '/login',
      component: Login,
      name: 'login',
      meta: {
        footerIsShow: true
      }
    },
    {
      path: '/register',
      component: Register,
      name: 'register',
      meta: {
        footerIsShow: true
      }
    },
    {
      path: '/detail/:skuId',
      component: Detail,
      name: 'detail',
    },
    {
      path: '/addCartSuccess',
      component: AddCartSuccess,
      name: 'addCartSuccess',
    },
    {
      path: '/shopCart',
      component: ShopCart,
      name: 'shopCart',
    },
    { path: '/search/:keyword?', component: Search, name: 'search' },
    { path: '/', redirect: '/home' }
  ]
})